package com.shouxin.attendance.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.shouxin.attendance.constants.PrefKey;
import com.shouxin.attendance.database.dao.DaoMaster;
import com.shouxin.attendance.utils.SharedPref;

import org.apache.log4j.Logger;
import org.greenrobot.greendao.database.Database;

import static com.shouxin.attendance.database.dao.DaoMaster.dropAllTables;

/**
 * @author jqg on 2017/3/16.
 */
class SQLiteOpenHelper extends DaoMaster.OpenHelper {

	private static final Logger logger = Logger.getLogger(SQLiteOpenHelper.class);

	public SQLiteOpenHelper(Context context, String name) {
		super(context, name);
	}

	SQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory) {
		super(context, name, factory);
	}

	@Override
	public void onUpgrade(Database db, int oldVersion, int newVersion) {
		logger.info("Upgrading schema from version " + oldVersion + " to " + newVersion + " by dropping all tables");
		SharedPref.putString(PrefKey.UPDATE_TIME, "");

		dropAllTables(db, true);
		onCreate(db);
	}
}
